package com.jml.demo.simple;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;


/**
 * 生产者 同步发送
 */
public class SyncProducer {
    public static void main(String[] args) throws Exception {
        //构建生产者示例，参数是生产者的组名
        DefaultMQProducer producer = new
                DefaultMQProducer("please_rename_unique_group_name");
        //指定nameserver地址
        producer.setNamesrvAddr("172.26.3.145:9876");
        //启动生产者示例
        producer.start();
        //
        for (int i = 0; i < 10; i++) {
            //构建消息的实例，topic 一级分类一定要有，tag 二级分类，body 消息体 ，消息的内容
            Message msg = new Message("TopicTest" /* Topic */,
                    "TagA" /* Tag */,
                    /*消息内容 */
                    ("Hello RocketMQ 同步发送" + i).getBytes(RemotingHelper.DEFAULT_CHARSET)
            );
            //消息指定一个key，可以做链路追踪
            msg.setKeys("key-"+i); //key ，链接追踪
            //发送消息，同步发送，会接收响应的结果
            SendResult sendResult = producer.send(msg);
            System.out.printf("%s%n", sendResult);
        }
        //关闭生产者实例
        producer.shutdown();
    }
}

/*
*
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CED80000, offsetMsgId=AC1A039100002A9F000000000002ED92, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=3], queueOffset=250]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CEE60001, offsetMsgId=AC1A039100002A9F000000000002EE67, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=0], queueOffset=250]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CEEB0002, offsetMsgId=AC1A039100002A9F000000000002EF3C, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=1], queueOffset=250]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CEF10003, offsetMsgId=AC1A039100002A9F000000000002F011, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=2], queueOffset=250]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CEF60004, offsetMsgId=AC1A039100002A9F000000000002F0E6, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=3], queueOffset=251]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CF050005, offsetMsgId=AC1A039100002A9F000000000002F1BB, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=0], queueOffset=251]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CF0A0006, offsetMsgId=AC1A039100002A9F000000000002F290, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=1], queueOffset=251]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CF120007, offsetMsgId=AC1A039100002A9F000000000002F365, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=2], queueOffset=251]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CF170008, offsetMsgId=AC1A039100002A9F000000000002F43A, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=3], queueOffset=252]
SendResult [sendStatus=SEND_OK, msgId=7F0000013DA418B4AAC24F91CF220009, offsetMsgId=AC1A039100002A9F000000000002F50F, messageQueue=MessageQueue [topic=TopicTest, brokerName=DESKTOP-CN3VH7I, queueId=0], queueOffset=252]

* */
